import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [{
  path: '/404',
  component: resolve => require(['@/views/error-page/404'], resolve),
  hidden: true
},
{
  path: '/showmsg',
  component: Layout,
  children: [{
    path: '',
    component: resolve => require(['@/views/showmsg'], resolve),
    hidden: true,
    meta: {
      noCache: true
    }
  }]
},

{
  path: '/index/sso/tokenSync',
  component: Layout,
  children: [{
    path: '',
    component: resolve => require(['@/views/sso/tokenSync'], resolve),
    name: 'tokenSync',
    hidden: true,
    meta: {
      title: 'tokenSync',
    }
  }]
},
{
  path: '/index/sso/dev',
  component: Layout,
  children: [{
    path: '',
    component: resolve => require(['@/views/sso/dev'], resolve),
    name: 'dev',
    hidden: true,
    meta: {
      title: 'dev',
    }
  }]
}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

export const asyncRoutes = [{
  path: '/',
  component: Layout,
  redirect: '/homepage',
  children: [{
    path: '/homepage',
    component: resolve => require(['@/views/homepage'], resolve),
    name: 'homepage',
    meta: {
      title: '首页',
      icon: 'homepage',
      roles: ['admin']
    }
  }]
},
{
  path: '/workbench',
  component: Layout,
  meta: {
    title: '代理工作台',
    icon: 'workbench',
    roles: ['admin']
  },
  children: [{
    path: 'myagency',
    component: resolve => require(['@/views/myagency'], resolve),
    name: 'myagency',
    meta: {
      title: '商品管理',
      icon: 'menu-line',
      roles: ['admin']
    }
  },
  {
    path: 'myagencydetail:id',
    component: resolve => require(['@/views/myagency/myagencydetail'], resolve),
    name: 'myagencydetail',
    hidden: true,
    meta: {
      title: '我的商品详情',
      activeMenu: '/workbench/myagency',
      roles: ['admin']
    }
  }, {
    path: 'transaction',
    component: resolve => require(['@/views/myagency/transaction'], resolve),
    name: 'transaction',
    meta: {
      title: '资金明细',
      icon: 'menu-line',
      roles: ['admin']
    }
  }, {
    path: 'statistics',
    component: resolve => require(['@/views/myagency/statistics'], resolve),
    name: 'statistics',
    meta: {
      title: '资金统计',
      icon: 'menu-line',
      roles: ['admin']
    }
  }, {
    path: 'mycontract',
    component: resolve => require(['@/views/myagency/mycontract'], resolve),
    name: 'mycontract',
    meta: {
      title: '我的合同',
      icon: 'menu-line',
      roles: ['admin']
    }
  },
  ]
}, {
  path: '/agency',
  component: Layout,
  children: [{
    path: '',
    component: resolve => require(['@/views/agency'], resolve),
    name: 'agency',
    meta: {
      title: '海量货源',
      icon: 'hall',
      roles: ['admin']
    }
  }, {
    path: 'agencydetail:id',
    component: resolve => require(['@/views/agency/agencydetail'], resolve),
    name: 'agencydetail',
    hidden: true,
    meta: {
      title: '商品详情',
      activeMenu: '/agency',
      roles: ['admin'],
      noCache: true
    }
  }, {
    path: 'pay',
    component: resolve => require(['@/views/agency/pay'], resolve),
    name: 'pay',
    hidden: true,
    meta: {
      title: '支付',
      activeMenu: '/agency',
      roles: ['admin'],
      noCache: true
    }
  },
  {
    path: 'agencynodetail:id',
    component: resolve => require(['@/views/agency/agencynodetail'], resolve),
    name: 'agencynodetail',
    hidden: true,
    meta: {
      title: '无订金商品详情',
      activeMenu: '/agency',
      roles: ['admin'],
      noCache: true
    }
  }, {
    path: 'payno',
    component: resolve => require(['@/views/agency/payno'], resolve),
    name: 'payno',
    hidden: true,
    meta: {
      title: '无订金支付',
      activeMenu: '/agency',
      roles: ['admin'],
      noCache: true
    }
  }
  ]
},
{
  path: '/help',
  component: Layout,
  children: [{
    path: '',
    component: resolve => require(['@/views/error-page/404'], resolve),
    name: 'help',
    hidden: true,
    meta: {
      title: '帮助中心',
      icon: 'help',
      roles: ['admin']
    }
  }]
}, {
  path: '/accountSettings',
  component: Layout,
  children: [{
    path: 'baseInfo',
    component: resolve => require(['@/views/accountSettings/baseInfo/index'], resolve),
    name: 'baseInfo',
    meta: {
      // title: '基本信息',
      title: '账户设置',
      // icon: 'menu-line',
      icon: 'mycontract',
      roles: ['admin']
    }
  },
  {
    path: 'sendEmail',
    component: resolve => require(['@/views/accountSettings/baseInfo/sendEmail'], resolve),
    name: 'sendEmail',
    hidden: true,
    meta: {
      title: '绑定邮箱',
      icon: 'menu-line',
      roles: ['admin']
    }
  }]
}, {
  path: '/authentication',
  component: Layout,
  hidden: true,
  meta: {
    title: '成为代理商',
    roles: ['admin']
  },
  children: [{
    path: 'index',
    component: resolve => require(['@/views/authentication/index'], resolve),
    name: 'explain',
    hidden: false,
    meta: {
      title: '认证说明',
      roles: ['admin']
    }
  }, {
    path: 'personal',
    component: resolve => require(['@/views/authentication/personal'], resolve),
    name: 'personal',
    hidden: false,
    meta: {
      title: '个人认证',
      roles: ['admin']
    }
  }, {
    path: 'enterprise',
    component: resolve => require(['@/views/authentication/enterprise'], resolve),
    name: 'enterprise',
    hidden: false,
    meta: {
      title: '企业认证',
      roles: ['admin']
    }
  }, {
    path: 'contractServices',
    component: resolve => require(['@/views/authentication/contractServices'], resolve),
    name: 'contractServices',
    hidden: false,
    meta: {
      title: '合同服务',
      roles: ['admin']
    }
  }, {
    path: 'contractSign',
    component: resolve => require(['@/views/authentication/contractSign'], resolve),
    name: 'contractSign',
    hidden: false,
    meta: {
      title: '签署合同',
      roles: ['admin']
    }
  }]
}, {
  path: '/monitor',
  component: Layout,
  redirect: '/monitor',
  children: [{
    path: '/monitor',
    component: resolve => require(['@/views/monitor/index'], resolve),
    name: 'monitor',
    meta: {
      title: '实时监控',
      icon: 'example',
      roles: ['admin']
    }
  }]
}, {
  path: '*',
  redirect: '/404',
  hidden: true
}
]

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // 重置路由器
}

export default router